package com.lz.autotest.project.system.controller;

import com.lz.autotest.common.aspectj.lang.annotation.Log;
import com.lz.autotest.common.aspectj.lang.enums.BusinessType;
import com.lz.autotest.common.utils.StringUtils;
import com.lz.autotest.common.web.controller.BaseController;
import com.lz.autotest.common.web.domain.AjaxResult;
import com.lz.autotest.common.web.page.TableDataInfo;
import com.lz.autotest.project.system.domain.perm.*;
import com.lz.autotest.project.system.service.ISysDeptPermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/system/deptPerm")
public class SysDeptPermController extends BaseController
{
    @Autowired
    private ISysDeptPermService deptPermService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDeptPerm sysDeptPerm)
    {
        startPage();
        List<SysDeptPerm> list = deptPermService.selectTsysDeptPermList(sysDeptPerm);
        return getDataTable(list);
    }



    /**
     * 获取部门权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @GetMapping(value = { "/","/{deptId}" })
    public AjaxResult getInfo(@PathVariable (value = "deptId",required = false) String deptId)
    {
        AjaxResult ajax = AjaxResult.success();
        if (StringUtils.isNotNull(deptId))
        {
            SysDeptPerm deptPerm = deptPermService.selectTsysDeptPermByDeptId(deptId);
            ajax.put(AjaxResult.DATA_TAG, deptPerm);
        }
        return ajax;
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:add')")
    @Log(title = "【用户权限管理】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDeptPerm tsysDeptPerm)
    {
        return toAjax(deptPermService.insertTsysDeptPerm(tsysDeptPerm));
    }

    /**
     * 修改部门权限
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:edit')")
    @Log(title = "【用户权限管理】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDeptPerm tsysDeptPerm)
    {
        return toAjax(deptPermService.updateTsysDeptPerm(tsysDeptPerm));
    }

    /**
     * 清空用户权限
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:remove')")
    @Log(title = "【用户权限管理】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable String[] deptIds)
    {
        deptPermService.clearDeptPermDetail(deptIds);
        return toAjax(deptPermService.deleteTsysDeptPermByDeptIds(deptIds));
    }

    /**
     * 获取用户权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @RequestMapping("/deptAccDetailPerm.action")
    public TableDataInfo deptAccDetailPerm(@RequestBody AccDept accDept)
    {
        List<AccDept> list = deptPermService.selectDeptAccPermList(accDept);
        return getDataTable(list);
    }
    /**
     * 获取用户权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @RequestMapping("/deptGroupDetailPerm.action")
    public TableDataInfo deptGroupDetailPerm(@RequestBody GroupDept groupDept)
    {
        List<GroupDept> list = deptPermService.selectDeptGroupPermList(groupDept);
        return getDataTable(list);
    }
    /**
     * 获取部门利率权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @RequestMapping("/deptIrcDetailPerm.action")
    public TableDataInfo deptIrcDetailPerm(@RequestBody IrcDept ircDept)
    {
        List<IrcDept> list = deptPermService.selectDeptIrcPermList(ircDept);
        return getDataTable(list);
    }

    /**
     * 获取部门红利权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @RequestMapping("/deptDivDetailPerm.action")
    public TableDataInfo deptDivDetailPerm(@RequestBody DivDept divDept)
    {
        List<DivDept> list = deptPermService.selectDeptDivPermList(divDept);
        return getDataTable(list);
    }
    /**
     * 获取部门波动率权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @RequestMapping("/deptVlsetailPerm.action")
    public TableDataInfo deptDivDetailPerm(@RequestBody VlsDept vlsDept)
    {
        List<VlsDept> list = deptPermService.selectDeptVlsPermList(vlsDept);
        return getDataTable(list);
    }


    /**
     * 获取用户权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptperm:list')")
    @RequestMapping("/deptCfgDetailPerm.action")
    public TableDataInfo deptCfgDetailPerm(@RequestBody CfgDept cfgDept)
    {
        List<CfgDept> list = deptPermService.selectDeptCfgPermList(cfgDept);
        return getDataTable(list);
    }
}
